package com.ftg.learn.pubsub;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 布衣
 */
public class Consumer1 {

    public static void main(String[] args) throws IOException, TimeoutException {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        factory.setPort(5672);
        factory.setVirtualHost("/");
        factory.setUsername("admin");
        factory.setPassword("admin");
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        channel.exchangeDeclare(Product.exName,"fanout");

        String queueName = channel.queueDeclare().getQueue();
        System.out.println(queueName+"===>1");
        channel.queueBind(queueName, Product.exName, "");
        channel.basicConsume(queueName, (x,y)->{
            System.out.println(" [x] Received '" + new String(y.getBody(), "UTF-8") + "'状态=>"+x);
        }, (consumerTag, message) -> {
        });
    }

}
